package com.mall.service.commodity.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.PmsProductCategory;
import com.mall.model.dto.ProductCategoryParam;
import com.mall.model.vo.CategoryChildrenVo;
import com.mall.service.commodity.service.PmsProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ProductCategoryController
 * @Description 商品分类
 * @Author dcq
 * @Date 2023/3/12 19:35
 * @Version 1.0
 */
@RestController
@RequestMapping("/productCategory")
public class ProductCategoryController {
    @Autowired
    private PmsProductCategoryService pmsProductCategoryService;
    //添加商品分类
    @PostMapping("/create")
    public CommonResult  create(@RequestBody PmsProductCategory pmsProductCategory){
        pmsProductCategoryService.createSei(pmsProductCategory);
        return CommonResult.success(null,"添加成功");
    }
    //删除
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id){
        pmsProductCategoryService.seleteSei(id);
        return  CommonResult.success(null,"删除成功");
    }
    //查询所有一级分类及子分类
    @GetMapping("/list/withChildren")
    public  CommonResult<List<CategoryChildrenVo>> list(){
         List<CategoryChildrenVo> vo= pmsProductCategoryService.listWcsei();
          return  CommonResult.success(vo);
    }
    //分页查询商品分类
    @GetMapping("/list/{parentId}")
    public  CommonResult<CommonPage> listPid(
            @RequestParam(defaultValue="1")Integer pageNum,
            @RequestParam(defaultValue = "10")Integer pageSize,
            @PathVariable Integer parentId
    ){
     CommonPage myPage= pmsProductCategoryService.page(pageNum,pageSize,parentId);
     return CommonResult.success(myPage);
    }
    //修改导航栏显示状态
    @PostMapping("/update/navStatus")
    public  CommonResult updateNs(String[]ids,Integer navStatus){
          pmsProductCategoryService.updateSei(ids,navStatus);
          return  CommonResult.success(null,"修改成功");
    }
    //修改显示状态
    @PostMapping("/update/showStatus")
    public  CommonResult updateSs   (String[]ids,Integer showStatus){
        pmsProductCategoryService.updateSsei(ids,showStatus);
        return  CommonResult.success(null,"修改成功");
    }
    //修改商品分类
    @PostMapping("/update/{id}")
    public  CommonResult  updateId(@PathVariable  Integer id, @RequestBody  ProductCategoryParam productCategory){
        pmsProductCategoryService.updateIdSei(id,productCategory);
        return  CommonResult.success(null,"修改成功");
    }
    //根据id获取商品分类
    @GetMapping("/{id}")
    public CommonResult<PmsProductCategory>getId(@PathVariable Integer id){
       PmsProductCategory pmsProductCategory= pmsProductCategoryService.getById(id);
       return  CommonResult.success(pmsProductCategory);
    }
}